from common.Ulitys import ForumDriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time


class ForumPost:
    def __init__(self):
        self.driver = ForumDriver.driver
        
    def Post(self):
        # 回到主页
        self.driver.find_element(By.CSS_SELECTOR,"#nav_board_index > a").click()
        time.sleep(1)
        # 点击发布帖子
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-header.d-print-none > div > div > div.col-auto.ms-auto.d-print-none > div > a.btn.btn-primary.d-none.d-sm-inline-block.article_post").click()
        time.sleep(1)
        # 标题
        self.driver.find_element(By.CSS_SELECTOR,"#article_post_title").send_keys("自动化测试帖子")
        # 内容
        self.driver.find_element(By.CSS_SELECTOR,"#edit-article > div.editormd-toolbar > div > ul > li:nth-child(6) > a").click()
        # 点击发布
        self.driver.execute_script("window.scrollTo(0,document.body.scrollHeight)")
        time.sleep(1)
        self.driver.find_element(By.CSS_SELECTOR,"#article_post_submit").click()
        # 检查是否发布成功
        time.sleep(1)
        text=self.driver.find_element(By.CSS_SELECTOR,"body > div.jq-toast-wrap.bottom-right > div > h2").text
        assert text=="成功"
        ForumDriver.getScreenShot()
        
        
        

